#include <iostream>
#include <map>
using namespace std;

int main(){
    //定义
    map<int, string> m;
       map<int, string> m1 = {
        {1, "one"}, {2, "two"}
    };

    map<int, string> m2 = {
        pair<int, string>(1, "one"), pair<int,string>(2, "two")
    };
    //添加
    m[1] = "one";
    m1.insert(pair<int, string>(1, "one"));
    m2.insert({1, "one"});
    
    //遍历
    for(map<int, string>::iterator it = m1.begin(); it != m1.end(); it++){
        cout<<it->first<<" : "<<it->second<<endl;
    }
    //查找
    cout<<1<<"->"<<m1[1]<<endl; //根据键查找 map[key] : value
    
    auto it = m1.find(2);   //map.find(key) 返回迭代器指向键值对
    cout<<it->first<<" : "<<it->second<<endl;
    //删除
    m1.erase(1);    //删除键为1的键值对
    //判断是否为空
    if(m1.empty()) cout<<"map为空"<<endl;
    else cout<<"map不为空"<<endl;

    cout<<"size:"<<m1.size()<<endl;
    return 0;
}